import { CheckboxValueType } from "antd/es/checkbox/Group";
import ApiClient from ".";
import { objectWithEmpty } from "@/utils/fun";
import md5 from "js-md5";

const api = new ApiClient("http://localhost:3000");

interface UserInfo {
  token: string;
  userInfo: {
    avatarUrl: string;
    nickname: string;
    phone: string;
    roleType: number;
    _id: number;
  };
}

export interface Comments {
  content: string;
  forumID: string;
  userID: string;
  _id: number;
  created_at: number;
}

// 登录
export async function login(params: any = {}) {
  const data = {
    ...params,
    password: md5(params.password),
  };
  console.log(data);
  return await api.post<UserInfo>("/api/user/login", data);
}

// 注册
export async function register(params: any = {}) {
  return await api.post("/api/user/register", params);
}

// 添加评论
export async function addComment(params: any = {}) {
  return await api.post("/addComment", params);
}

// 获取评论
export async function getComments(params: any = {}) {
  return await api.post<Comments[]>("/comments", params);
}

// 发布文章
export async function addPosts(params: any = {}) {
  return await api.post<Comments[]>("/addPosts", params);
}
